В любом случае Ваши объекты подчинены некоторой иерархии. Например, у вас может быть много объектов автомобилей, которые находятся в гараже.

Так же в приложении Excel, есть много листов, в базе данных много таблиц. В общем можно сказать, что у нас могут быть наборы объектов с одинаковой функциональностью. Объекты, которые содержат в себе однотипные объекты назваются коллекциями (Collection). В данном случае можно сказать, что гараж - это коллекция. Создавать коллекцию удобно используя ClassWizard. В нем есть специальная кнопка для реализации данной возможности.

Давайте создадим новый проект ActiveX DLL вот с такой структурой:

И вызовем Class Builder, нажав на кнопку AddNewCollection. Здесь нам нужно будет указать имя коллекции и класс, который будет в эту коллекцию входить.

После нажатия на OK вы увидите изменения в окне Class Builder.

После обновления проекта Class Builder сформирует весь необходимый код в новом классе коллекции.

'local variable to hold collection
Private mCol As Collection
Public Function Add(Optional sKey As String) As ClassAuto
'create a new object
Dim objNewMember As ClassAuto
Set objNewMember = New ClassAuto
'set the properties passed into the method
If Len(sKey) = 0 Then
mCol.Add objNewMember
Else
mCol.Add objNewMember, sKey
End If
'return the object created
Set Add = objNewMember
Set objNewMember = Nothing
End Function
Public Property Get Item(vntIndexKey As Variant) As ClassAuto
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set Item = mCol(vntIndexKey)
End Property
Public Property Get Count() As Long
'used when retrieving the number of elements in the
'collection. Syntax: Debug.Print x.Count
Count = mCol.Count
End Property
Public Sub Remove(vntIndexKey As Variant)
'used when removing an element from the collection
'vntIndexKey contains either the Index or Key, which is why
'it is declared as a Variant
'Syntax: x.Remove(xyz)
mCol.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
'this property allows you to enumerate
'this collection with the For...Each syntax
Set NewEnum = mCol.[_NewEnum]
End Property
Private Sub Class_Initialize()
'creates the collection when this class is created
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
'destroys collection when this class is terminated
Set mCol = Nothing
End Sub
Обратите внимание, что была создана внутренняя переменная типа Collection и функция для доступа к ней. Естественно, что все это можно было написать и руками, но все же.